package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.pro.domain.dao.AiAssistantConfigDao;
import com.xbongbong.pro.domain.entity.AiAssistantConfigEntity;
import com.xbongbong.saas.model.AiAssistantConfigModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 智能助手配置
 * @Author: hongxiao
 * @date: 2019-05-10 10:41
 * @since v1.0
 */
@Service("ssConfigModel")
public class AiAssistantConfigModelImpl implements AiAssistantConfigModel {
    @Resource
    private AiAssistantConfigDao aiAssistantConfigDao;

    @Override
    public Integer insert(AiAssistantConfigEntity entity){
        return aiAssistantConfigDao.insert(entity);
    }

    @Override
    public Integer update(AiAssistantConfigEntity entity){
        return aiAssistantConfigDao.update(entity);
    }

    @Override
    public List findEntitys(Map<String, Object> param) {
        return aiAssistantConfigDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return aiAssistantConfigDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public Integer save(AiAssistantConfigEntity entity){

        if(entity.getId() == null || entity.getId().equals(0L)) {
            return aiAssistantConfigDao.insert(entity);
        }
        return aiAssistantConfigDao.update(entity);
    }

    @Override
    public void insertBatch(List<AiAssistantConfigEntity> entityList) {
        aiAssistantConfigDao.insertBatch(entityList);
    }

    @Override
    public AiAssistantConfigEntity getByCorpid(String corpid) {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("corpid", corpid);
        param.put("del", DelEnum.NORMAL.getDel());
        List<AiAssistantConfigEntity> list = findEntitys(param);
        if(list == null || list.size() == 0) {
            return null;
        }
        return list.get(0);
    }
}
